<template>
  <el-dialog
    title="设置"
    :visible.sync="$attrs.visableIf"
    @close="handleCloseDialog"
    width="600px"
    append-to-body
    class="borderb_dia"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      size="small"
      label-width="130px"
      label-position="left"
    >
      <el-form-item label="任务休眠时段：" prop="checked" class="delay">
        <el-checkbox v-model="form.checked"
          ><span class="c_text">启用</span>
        </el-checkbox>
      </el-form-item>
      <el-form-item prop="checkList" class="delay">
        <template slot="label">
          <span
            >消息发送间隔
            <el-tooltip
              class="item"
              effect="dark"
              content="同一个对象的上一条消息发送完毕到下一条消息开始发送的间隔时间。"
              placement="top-start"
            >
              <svg-icon icon-class="iquestion" class-name="c_888999 f-15" />
            </el-tooltip>
            :
          </span>
        </template>
        <div class="f_content flex">
          <el-input
            v-model="form.min"
            placeholder=""
            style="width: 78px"
            class="mr-5"
            @blur="onBlur('min')"
          ></el-input>
          秒
          <span class="divi"> - </span>
          <el-input
            v-model="form.max"
            placeholder=""
            style="width: 78px"
            class="mr-5"
            @blur="onBlur('max')"
          ></el-input>
          秒
          <span class="c_primary commhover pl-10" @click="handleDefault"
            >设为推荐值</span
          >
        </div>
      </el-form-item>
      <div class="c_text3">提示：消息发送不宜太频繁，注意账号风险！</div>
    </el-form>
    <div slot="footer">
      <el-button size="small" @click="handleCloseDialog">取消</el-button>
      <el-button size="small" type="primary" @click="submitForm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import { validPhone, validPassword } from "@/utils/validate";
// import { editInfo } from "@/api/advmaster";
export default {
  data() {
    return {
      form: {
        name: "",
        min: 5,
        max: 10,
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        email: [
          {
            required: true,
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: "blur",
          },
        ],
        password: [],
        status: [{ required: true, message: "请选择状态", trigger: "change" }],
      },
    };
  },
  props: {
    rowitem: {
      default: null,
    },
  },
  created() {},
  methods: {
    handleCloseDialog() {
      this.$emit("update:visableIf", false);
    },

    onBlur(type) {
      // 使用正则表达式匹配正整数
      const regex = /^[1-9]\d*$/;
      // 如果输入的值不是正整数，则将其设置为上一个有效值
      if (!regex.test(this.form[type])) {
        if (type == "min") {
          this.form.min = 5;
        } else {
          this.form.max = 10;
        }
      } else {
        if (this.form[type] > 999) {
          this.form[type] = 999;
        }
      }
    },

    handleDefault() {
      this.form.min = 5;
      this.form.max = 10;
    },

    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            // editInfo(this.form).then(() => {
            //   this.$modal.msgSuccess('修改成功')
            //   this.handleCloseDialog();
            //   this.$emit('getList');
            // })
          }
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.delay {
  background: #f0f0f0;
  border: 1px solid #e9e9e9;
  padding: 7px 14px;
  margin-bottom: 8px;
}
.divi {
  display: inline-block;
  margin: 0 6px;
}
</style>
